﻿@model Xuanren_FrontEnd.Model.User
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Add</title>
    <link href="~/Content/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/lib/layui/layui.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <input type="text" hidden value="@Model.id" id="uid" />
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" id="name" value="@Model.name" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="tel" id="phone" value="@Model.phone" required lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <select id="sex" name="sex" lay-verify="" lay-search="">
                    @if (Model.sex == "1")
                    {
                        <option value="@Model.sex">女</option>
                    }
                    else
                    {
                        <option value="@Model.sex">男</option>
                    }
                    <optgroup label="性别">
                        <option value="0">男</option>
                        <option value="1">女</option>
                    </optgroup>

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select id="status" name="status" lay-verify="" lay-search="">
                    @if (Model.status == "1")
                    {
                        <option value="@Model.status">正常</option>
                    }
                    else
                    {
                        <option value="@Model.status">已禁用</option>
                    }
                    <optgroup label="状态">
                        <option value="0">已禁用</option>
                        <option value="1">正常</option>
                    </optgroup>

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        //Demo
        layui.use(['form', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.$;
            //监听提交
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    url: "/Back/User/update",
                    type: "post",
                    data: {
                        id: $("#uid").val(),
                        name: $("#name").val(),
                        sex: $("#sex").val(),
                        phone: $("#phone").val(),
                        status: $("#status").val(),
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            parent.layer.close()
                            parent.location.reload()
                        }
                    }
                })
                return false;
            });
        });
    </script>
</body>
</html>
